package dst.ass1.jpa.model.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import dst.ass1.jpa.model.ITaskForce;
import dst.ass1.jpa.model.ITaskProcessing;
import dst.ass1.jpa.model.ITaskWorker;
import dst.ass1.jpa.validator.WorkUnitCapacity;

//in TaskWorker.xml specified
//alternative with @EntityListener(value=WorkerListener.class)
public class TaskWorker implements ITaskWorker{

	private final static Logger LOGGER = Logger.getLogger(TaskWorker.class.getName());
	
	private Long id;
	
	@Size(min=5, max=25)  ///1.3.a. every worker has a name not shorter than 5 and no longer than 25 characters.
	private String name;
	
	@WorkUnitCapacity(min = 4, max = 8) //1.3.b platform only uses workers, which have a specific amount of capacity.
	private Integer workUnits;
	
	@Pattern(regexp="[A-Z]{3}-[A-Z]{3}@\\d{4,}")  //1.3.a. for example "AUT-VIE@1040"
	private String location;
	
	@Past			//1.3.a. A worker has dates for joined and lastTraining, both have to be in the past.
	private Date joined;
	
	@Past			//1.3.a. A worker has dates for joined and lastTraining, both have to be in the past.
	private Date lastTraining;
	
	private ITaskForce taskForce;
	
	private List<ITaskProcessing> taskProcessings;
	
	public TaskWorker (){
		this.taskProcessings = new ArrayList<ITaskProcessing>();
	}
	
	@Override
	public Long getId() {
		return id;
	}
	
	@Override
	public void setId(Long id) {
		this.id=id;
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName(String name) {
		this.name=name;
	}
	
	@Override
	public Integer getWorkUnitCapacity() {
		return workUnits;
	}
	
	@Override
	public void setWorkUnitCapacity(Integer workUnits) {
		this.workUnits=workUnits;	
	}
	
	@Override
	public String getLocation() {
		return location;
	}
	
	@Override
	public void setLocation(String location) {
		this.location=location;
	}
	
	@Override
	public Date getJoinedDate() {
		return joined;
	}
	
	@Override
	public void setJoinedDate(Date joined) {
		this.joined=joined;
	}
	
	@Override
	public Date getLastTraining() {
		return lastTraining;
	}
	
	@Override
	public void setLastTraining(Date lastTraining) {
		this.lastTraining=lastTraining;
	}
	
	@Override
	public ITaskForce getTaskForce() {
		return taskForce;
	}
	
	@Override
	public void setTaskForce(ITaskForce taskForce) {
		this.taskForce=taskForce;
	}
	
	@Override
	public List<ITaskProcessing> getTaskProcessings() {
		return taskProcessings;
	}
	
	@Override
	public void setTaskProcessings(List<ITaskProcessing> processings) {
		this.taskProcessings=processings;
	}
	
	
	@Override
	public void addTaskProcessing(ITaskProcessing processing) {
		if(this.taskProcessings!=null){
			this.taskProcessings.add(processing);
		}
		else{
			LOGGER.info("TaskWorker.List<ITaskProcessing> was null");
		}
		
	}

}
